Warning: mkdir(): No space left on device in /var/www/tg-me/post.php on line 37

Warning: file_put_contents(aCache/aDaily/post/golangtests/--): Failed to open stream: No such file or directory in /var/www/tg-me/post.php on line 50
Go tests | Telegram Webview: golangtests/777 -
Telegram Group & Telegram Channel
🧠 Хитрая задача на Go (v1.22+) — алгоритмы, циклы и подвох в логике

📌 Задача: "Подряд идущие квадраты"

Дано: массив из N положительных целых чисел []int, например:


[]int{1, 4, 9, 16, 25, 36, 50, 64, 81}


Нужно найти максимальную длину подмассива, где все элементы — квадраты подряд идущих натуральных чисел.

Например, [4, 9, 16, 25] — это квадраты 2², 3², 4², 5² → длина = 4
[50, 64] — не подходят, так как 50 не является точным квадратом.

🎯 Формат функции:


func MaxConsecutiveSquares(nums []int) int


Пример:


input := []int{1, 4, 9, 16, 25, 36, 50, 64, 81}
fmt.Println(MaxConsecutiveSquares(input)) // 👉 6


🧩 Подвох:

- Часто пытаются сравнивать разности или применять хэшмапы — но это ошибка
- Нужно восстановить корни чисел (`sqrt`) и убедиться, что они натуральные и идут подряд
- Важно использовать math.Sqrt и быть осторожным с плавающей точкой (`float64`)
- Также важно не выходить за границы slice

💡 Подсказка:

```go
import "math"

func isSquare(n int) (int, bool) {
root := int(math.Sqrt(float64(n)))
return root, root*root == n
}
```

🛠 **Что проверяет задача:**

• Умение работать с нецелыми корнями
• Алгоритмы "двойного указателя" (две границы окна)
• Понимание строгой проверки на натуральные числа
• Внимание к float64-погрешности и типам



tg-me.com/golangtests/777
Create:
Last Update:

🧠 Хитрая задача на Go (v1.22+) — алгоритмы, циклы и подвох в логике

📌 Задача: "Подряд идущие квадраты"

Дано: массив из N положительных целых чисел []int, например:


[]int{1, 4, 9, 16, 25, 36, 50, 64, 81}


Нужно найти максимальную длину подмассива, где все элементы — квадраты подряд идущих натуральных чисел.

Например, [4, 9, 16, 25] — это квадраты 2², 3², 4², 5² → длина = 4
[50, 64] — не подходят, так как 50 не является точным квадратом.

🎯 Формат функции:


func MaxConsecutiveSquares(nums []int) int


Пример:


input := []int{1, 4, 9, 16, 25, 36, 50, 64, 81}
fmt.Println(MaxConsecutiveSquares(input)) // 👉 6


🧩 Подвох:

- Часто пытаются сравнивать разности или применять хэшмапы — но это ошибка
- Нужно восстановить корни чисел (`sqrt`) и убедиться, что они натуральные и идут подряд
- Важно использовать math.Sqrt и быть осторожным с плавающей точкой (`float64`)
- Также важно не выходить за границы slice

💡 Подсказка:

```go
import "math"

func isSquare(n int) (int, bool) {
root := int(math.Sqrt(float64(n)))
return root, root*root == n
}
```

🛠 **Что проверяет задача:**

• Умение работать с нецелыми корнями
• Алгоритмы "двойного указателя" (две границы окна)
• Понимание строгой проверки на натуральные числа
• Внимание к float64-погрешности и типам

BY Go tests


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/golangtests/777

View MORE
Open in Telegram


Go tests Telegram | DID YOU KNOW?

Date: |

Should You Buy Bitcoin?

In general, many financial experts support their clients’ desire to buy cryptocurrency, but they don’t recommend it unless clients express interest. “The biggest concern for us is if someone wants to invest in crypto and the investment they choose doesn’t do well, and then all of a sudden they can’t send their kids to college,” says Ian Harvey, a certified financial planner (CFP) in New York City. “Then it wasn’t worth the risk.” The speculative nature of cryptocurrency leads some planners to recommend it for clients’ “side” investments. “Some call it a Vegas account,” says Scott Hammel, a CFP in Dallas. “Let’s keep this away from our real long-term perspective, make sure it doesn’t become too large a portion of your portfolio.” In a very real sense, Bitcoin is like a single stock, and advisors wouldn’t recommend putting a sizable part of your portfolio into any one company. At most, planners suggest putting no more than 1% to 10% into Bitcoin if you’re passionate about it. “If it was one stock, you would never allocate any significant portion of your portfolio to it,” Hammel says.

Newly uncovered hack campaign in Telegram

The campaign, which security firm Check Point has named Rampant Kitten, comprises two main components, one for Windows and the other for Android. Rampant Kitten’s objective is to steal Telegram messages, passwords, and two-factor authentication codes sent by SMS and then also take screenshots and record sounds within earshot of an infected phone, the researchers said in a post published on Friday.

Go tests from us


Telegram Go tests
FROM USA